package internal

import (
	"github.com/spf13/cobra"
)

var (
	migrate bool
	gendao  bool
)

// startCmd represents the start command
var RootCmd = &cobra.Command{
	Use:  "main",
	RunE: startRun,
}

func startRun(cmd *cobra.Command, args []string) error {
	if migrate {
		Migrate()
		return nil
	}

	if gendao {
		Gormgen()
		return nil
	}
	if len(args) == 0 {
		cmd.Help()
		return nil
	}
	return nil
}

func init() {
	initConfig()
	initDb()

	RootCmd.PersistentFlags().BoolVarP(&migrate, "migrate", "m", false, "迁移结构体到数据库表")
	RootCmd.PersistentFlags().BoolVarP(&gendao, "gendao", "g", false, "生成dao和model")
}
